<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增活动')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-activity-add">
            <h4 class="form-header h4">活动信息</h4>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">活动名称：</label>
                <div class="col-sm-8">
                    <input name="activityName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">活动封面：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="cover">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="coverFile" name="coverFile" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">活动小结：</label>
                <div class="col-sm-8">
                    <textarea name="activitySummary" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">活动照片：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="activityPictures">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="activityPictureFiles" name="activityPictureFiles" type="file" multiple>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">新闻稿：</label>
                <div class="col-sm-8">
                    <textarea name="newsRelease" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">项目：</label>
                <div class="col-sm-8">
                    <!--<input name="projectId" class="form-control" type="text">-->
                    <select name="projectId" class="form-control">
                        <option value="">--请选择--</option>
                        <option th:each="item:${projectList}"
                                th:value="${item.id}" th:text="${item.projectName}"
                                th:selected="*{projectId}==${item.id}">
                        </option>
                    </select>
                </div>
            </div>
            <h4 class="form-header h4">活动标准信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "system/activity"
        $("#form-activity-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form() && !$('.file-caption-name.form-control').hasClass('is-invalid')) {
                var formData = new FormData($("#form-activity-add")[0]);
                $.operate.save(prefix + "/add", formData, null, {
                    contentType: false,
                    processData: false
                });
            }
        }

        $(".file-upload").each(function (i) {
            $(this).fileinput({
                // 'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                maxFileCount: this.id == 'coverFile' ? 1 : 9,
                showUpload: false,
                initialPreviewShowDelete: false,
                showRemove: false,
                autoReplace: true,
                allowedFileExtensions: ['jpg', 'jpeg', 'png', 'gif']
            }).on('filebatchselected', function (event, files, previewId, index) {
            }).on('fileremoved', function (event, id, index) {
            })
            $(this).fileinput('_initFileActions');
        });

        $(function() {
            var options = {
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "",
                    width: 1,
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex;
                    }
                },
                {
                    field: 'standardName',
                    align: 'center',
                    title: '标准名称',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='cmsActivityStandardList[%s].standardName' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'standardValue',
                    align: 'center',
                    title: '标准值',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='cmsActivityStandardList[%s].standardValue' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'standardDefinition',
                    align: 'center',
                    title: '标准定义',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='cmsActivityStandardList[%s].standardDefinition' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'standardContent',
                    align: 'center',
                    title: '标准内容',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='cmsActivityStandardList[%s].standardContent' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'workerContent',
                    align: 'center',
                    title: '社工上传内容',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='cmsActivityStandardList[%s].workerContent' value='%s'>", index, value);
                        return html;
                    }
                },
                /*{
                    field: 'createTime',
                    align: 'center',
                    title: '',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='cmsActivityStandardList[%s].createTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'createBy',
                    align: 'center',
                    title: '',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='cmsActivityStandardList[%s].createBy' value='%s'>", index, value);
                        return html;
                    }
                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
            };
            $.table.init(options);
        });

        function addRow() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            var row = {
                index: $.table.serialNumber(count),
                standardName: "",
                standardValue: "",
                standardDefinition: "",
                standardContent: "",
                workerContent: "",
                createTime: "",
                createBy: "",
            }
            sub.addRow(row);
        }
    </script>
</body>
</html>
